﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using CrateMayhem.Common.Data;
using CrateMayhem.Common.Model;

namespace CrateMayhem.Desktop.Data
{
    public class WorldRepository : WorldRepositoryBase
    {
        static WorldRepository()
        {
            var uri = new Uri("pack://application:,,,/Assets/BoxWorld.txt");
            var info = Application.GetResourceStream(uri);

            if (info == null) return;

            using (var reader = new StreamReader(info.Stream))
            {
                var data = new List<string>();

                var line = reader.ReadLine();

                while (line != null)
                {
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        Worlds.Add(Create(data));
                        data.Clear();
                    }
                    else
                    {
                        data.Add(line);
                    }

                    line = reader.ReadLine();
                }

                Worlds.Add(Create(data));
            }
        }
    }
}
